import "dart:convert";

import "package:flutter/material.dart";
import "package:shared_preferences/shared_preferences.dart";

extension ExSharedPreferences on SharedPreferences {
  getJSON(String key, String defaultValue) =>
      jsonDecode(getString(key) ?? defaultValue);

  Future<bool> setJSON(String key, Object data) async {
    bool result = await setString(key, jsonEncode(data));
    return result;
  }
}

extension ExBoxDecoration on BoxDecoration {
  BoxDecoration merge(BoxDecoration? other) {
    if (other == null) return this;
    return copyWith(
      color: other.color,
      image: other.image,
      border: other.border,
      borderRadius: other.borderRadius,
      boxShadow: other.boxShadow,
      gradient: other.gradient,
      backgroundBlendMode: other.backgroundBlendMode,
      shape: other.shape,
    );
  }
}
